package com.zsr.rabbitmq.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zsr.rabbitmq.utils.RabbitMqUtils;

/**
 * 消费者 direct交换机  单播模式
 * @author zsr
 * @date 2021/8/7 19:44
 */
public class ReceiveLogsDirect01 {
    public static final String EXCHANGE_NAME="direct_logs";//交换机名
    public static final String QUEUE_NAME="console";//队列名

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();

        //声明第一个队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //绑定交换机和队列
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"info");
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"warning");

        DeliverCallback deliverCallback=(consumeTag, delivery)->{
            System.out.println("控制台接收到的消息："+new String(delivery.getBody(), "UTF-8"));
        };
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,consumeTag->{});

    }
}
